﻿// Generated on 2014-12-15 using
// generator-webapp 0.5.1
'use strict'

// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// If you want to recursively match all subfolders, use:
// 'test/spec/**/*.js'

module.exports = function(grunt) {

  // Time how long tasks take. Can help when optimizing build times
  require('time-grunt')(grunt)

  // Load grunt tasks automatically
  require('load-grunt-tasks')(grunt)


  // Configurable paths
  var config = {
    app: 'app',
    dist: 'dist'
  }

  var resourcesConfig={
    img:'img',
    css:'css',
    js:'js'
  }

  // Define the configuration for all the tasks
  grunt.initConfig({

    // Project settings
    config: config,
    // resources settings
    resourcesConfig:resourcesConfig,

    connect: {
      options: {
        port: 9001,
        open: true,
        livereload: 35730,
        hostname: '192.168.0.236' /*'127.0.0.1'*/
        /* base: '.'*/
      },

      dev: {
        options: {
          middleware: function(connect) {
            return [
              connect.static('.tmp'),
              connect.static(config.app)
            ]
          }
        }
      }

    },

    watch: {
      js: {
        files: ['<%= config.app %>/<%= resourcesConfig.js %>/{,*/}*.js']
        //tasks: ['jshint']
      },
      gruntfile: {
        files: ['Gruntfile.js']
      },
      styles: {
        files: ['<%= config.app %>/<%= resourcesConfig.css %>/{,*/}*.css']
        /*tasks: ['newer:copy:styles', 'autoprefixer']*/
      },
      /*compass: {
       files: ['<%= config.app %>/styles/*.{scss,sass}'],
       tasks: ['compass:dev']
       },*/
      livereload: {
        options: {
          livereload: '<%= connect.options.livereload %>'
        },
        files: [ //下面文件的改变就会实时刷新网页
          '<%= config.app %>/{,*/}*.html',
          '<%= config.app %>/<%= resourcesConfig.css %>/{,*/}*.css',
          '.tmp/styles/{,*/}*.css',
          '<%= config.app %>/<%= resourcesConfig.img %>/{,*/}*'
        ]
      }

    },

    /*compass: {
     dist: { // Target
     options: { // Target options
     sassDir: '<%= config.app %>/styles/',
     cssDir: '.tmp/styles/',
     //style: 'compressed', //以压缩模式编译css，
     environment: 'production'
     }
     },
     dev: { // Another target
     options: {
     sassDir: '<%= config.app %>/styles/',
     cssDir: '.tmp/styles/',
     }
     }
     },*/

    // Make sure code styles are up to par and there are no obvious mistakes
    jshint: {
      options: {
        jshintrc: '.jshintrc',
        reporter: require('jshint-stylish')
      },
      all: [
        'Gruntfile.js',
        '<%= config.app %>/scripts/{,*/}*.js',
        '!<%= config.app %>/scripts/vendor/*',
        'test/spec/{,*/}*.js'
      ]
    }

  })

  //grunt.loadNpmTasks('grunt-contrib-jshint')
  //grunt.loadNpmTasks('grunt-contrib-compass')
  //grunt.loadNpmTasks('grunt-contrib-watch')
  //grunt.loadNpmTasks('grunt-contrib-connect')

  grunt.registerTask('default', [ /*'newer:jshint','compass:dev',*/ 'connect:dev', 'watch'])

}
